<?php
namespace App\Models\Api;
use App\Models\Api\Base;
use Cache;

class HeText extends Base
{

    protected $table = 'he_text';

    /**
     * 获取所有合盘相位词条
     */
    public function getHeText()
    {
        $data = false;

        if (intval($this->cache_on) >= 1 && Cache::has('he_text')) {
            $data = Cache::get('he_text');
        }

        if ($data === false) {
            try
            {
                $data = $this->where('status', 0)->get();
                $data = json_decode(json_encode($data, true), true);
            } 
            catch (\Exception $e) {
                $data = [];
            }
            
            $temp = [];
            foreach ($data as $d) $temp[$d['planet'] . '-' . $d['phase']] = $d;
            $data = $temp;

            if (intval($this->cache_on) >= 1) {
                
                Cache::set('he_text', $data, 86400 * 7);
            }
        }

        return $data;
    }

}
